package chloroform.exec

import chloroform.{InstanceExecutorContext, InstanceExecutor}
import genstream.pump.Pump
import genstream.{InputResource, OutputResource}
import genstream.http.HttpRequestResource

/**
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: 16.4.11
 * Time: 12:58
 * To change this template use File | Settings | File Templates.
 */

object OutputResourceExecutor extends InstanceExecutor {
  def execute(instance: Any, context: InstanceExecutorContext) = {

    if (instance.isInstanceOf[OutputResource]) {

      val inputRes: InputResource = new HttpRequestResource(context.request)
      val outputRes: OutputResource = instance.asInstanceOf[OutputResource]
      val pump: Pump = new Pump(inputRes, outputRes)
      pump.run

    } else
      context.chain.execute

  }
}